<template>
	<view>
		<!-- 按组使用 -->
		<uni-swipe-action>
			<block v-for="(item,index) in datas" :key="index">
				<uni-swipe-action-item  :options="options" @click="onClick($event,item)" @change="change" v-if="tabCur==item.type" >
				<view class="cu-bar solid-bottom action"  style="padding-left: 10px;" >
					<!-- <uni-icons :type="item.name" :color="activeIndex === index?'#007aff':'#8f8f94'" size="25" /> -->
					<image :class="item.type==0?'expend':'income'"  :src="item.type==0?expend[item.active_id].url:income[item.active_id].url1" class="image" />
					<text :class="item.type==0?'expend':'income'" class="icon-item-text">{{ item.name }}</text>
					<text :class="item.type==0?'expend':'income'" style="padding-left: 10px;" class="icon-item-text">{{  item.create_time.split(" ")[0] }}</text>
					<!-- <text style="color:#1296db;padding-left: 10px;" class="icon-item-text">{{  new Date(item.create_time.split(" ")[0]).getTime() }}</text> -->
					<view class="solid-bottom padding" style="padding-left: 10px;">
						<text class="text-price">{{item.money}}</text>
					</view>
				</view>
			</uni-swipe-action-item>
			</block>
			
		</uni-swipe-action>
		<uni-load-more color="#8e8e8e" :status="loadMoreStatus" v-if="isShowLoadMore" iconType="auto" @clickLoadMore="clickLoadMore"
		 :content-text="contentText" />
		 <loading v-if="!datas[0]"></loading>
	</view>
</template>

<script>
	import uniSwipeAction from '../../../components/uni-swipe-action/uni-swipe-action.vue'
	import uniSwipeActionItem from '../../../components/uni-swipe-action-item/uni-swipe-action-item.vue'
	import uniLoadMore from '../../../components/uni-load-more/uni-load-more.vue'
	import {
		callCloudFunction,
		getUserOpenid
	} from '../../../common/public_util.js';
	let _self;
	export default {
		components: {
			uniSwipeAction,
			uniSwipeActionItem,
			uniLoadMore
		},
		props: {
			income:{
				type:Array, 
				default: []
			},
			expend:{
				type: Array, 
				default: []
			},
			cur:{
				type: Number, 
				default: []
			},
			tabCur:{
				type: Number, // 1-数字键盘 2-身份证号  -车牌号
				default: 0
			},
		},
		data() {
			return {
				col:"",
				options: [{
						text: '修改',
						style: {
							backgroundColor: '#007dd5'
						}
					},
					{
						text: '删除',
						style: {
							backgroundColor: '#dd524d'
						}
					},
				],
				isShowLoadMore: false, //是否显示上啦加载
				loadMoreStatus: 'more', //上啦加载状态，more加载前，loading加载中，noMore没有更多
				pageNumber: 1, //页码
				pageSize: 10, //加载数量
				contentText: {
					contentdown: '查看更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				},
				datas:[]
			}
		},
		created() {
			_self = this;
			this.col=this.$parent.col
			this.initData();
		},
		methods: {
			async initData(){
				let res=await uni.$request({},"bill/index/getBillList")
				this.datas=res.data
			},
			async onClick(e, item) {
				switch (e.index) {
					case 0: //修改
						uni.setStorageSync('modifyDetailed',item);
						this.$parent.billInfo=item
						this.$parent.go(0)
						break;
					case 1: //删除
						let res=await uni.$request({
							id:item.id
						},"bill/index/delBillInfo")
						if (res.code==200) {
							this.initData();
							uni.$success(res.msg)
						}else{
							uni.$err(res.msg)
						}
						break;
				}

			},
			change(open) {
				console.log('当前开启状态：' + open)
			},
			clickLoadMore: (e) => { //加载更多
				if (e.detail.status == 'more') {
					_self.pageNumber++;
					_self.onQuery(e);
				}
			},
			onQuery: (e) => {
				if (e == null || e.detail == null || e.detail.status != 'more') {
					_self.pageNumber = 1;
					_self.datas = [];
				}
				_self.isShowLoadMore = true;
				_self.loadMoreStatus = 'loading'; //loading加载中

				callCloudFunction('money_query', {
					openid: getUserOpenid(),
					pageNumber: _self.pageNumber,
					pageSize: _self.pageSize,
				}, (res) => {
					let total = res.total;
					_self.datas = _self.datas.concat(res.data);
					//全部
					if (_self.datas.length >= total) {
						_self.loadMoreStatus = 'noMore'; //noMore没有更多
					} else {
						_self.loadMoreStatus = 'more'; //more加载前
					}
				});
			}
		}
	}
</script>
<style lang="scss">
	@import "../main.scss";
	.image {
		width: 40rpx;
		height: 40rpx;
		margin-right: 20rpx;
		padding: 20rpx;
		box-sizing: content-box;
		border-radius: 100rpx;
	}
	image.income{
    	background: $col2;
	}
	image.expend{
		background: $col;
	}
	.income{
    	color: $col2;
	}
	.expend{
		color: $col;;
	}
</style>
<style>
	
</style>
